/**
 * Copyright (c) qc&Bull Co.,LTD.
 * All right reserved.
 */

package cn.zxd.lis.schema;

import cn.zxd.lis.db.LogSubjectDB;
import cn.zxd.util.*;

import java.sql.ResultSet;
import java.sql.SQLException;

/**
 * <p>ClassName: LogSubjectSchema </p>
 * <p>Description: DB层 Schema 类文件 </p>
 * <p>Company: qc&Bull Co.,LTD </p>
 * @Database: IIEP_Data_Model
 * @author：anonymous
 * @CreateDate：2015-11-22
 */
public class LogSubjectSchema implements Schema, Cloneable
{
    // @Field
    /** 日志主题ID */
    private String SubjectID;
    /** 日志主题描述 */
    private String SubjectDes;
    /** 日志监控部门 */
    private String Dept;
    /** 所属业务模块 */
    private String ServiceModule;
    /** 业务功能编码 */
    private String TaskCode;
    /** 业务功能描述 */
    private String TaskDescribe;
    /** 日志分类 */
    private String LogType;
    /** 日志监控域开关 */
    private String Switch;

    /** 数据库表的字段个数 */
    public static final int FIELDNUM = 8;

    /** 主键 */
    private static String[] PK;

    /** 错误信息 */
    public CErrors mErrors;

    // @Constructor
    public LogSubjectSchema()
    {
        mErrors = new CErrors();
        String[] pk = new String[1];
        pk[0] = "SubjectID";
        PK = pk;
    }

    /**
     * Schema克隆
     * @return Object
     * @throws CloneNotSupportedException
     */
    public Object clone() throws CloneNotSupportedException
    {
        LogSubjectSchema cloned = (LogSubjectSchema)super.clone();
        cloned.mErrors = (CErrors) mErrors.clone();
        return cloned;
    }

    // @Method
    public String[] getPK()
    {
        return PK;
    }

    public String getSubjectID()
    {
        return SubjectID;
    }

    public void setSubjectID(String aSubjectID)
    {
        SubjectID = StrTool.cTrim(aSubjectID);
    }

    public String getSubjectDes()
    {
        return SubjectDes;
    }

    public void setSubjectDes(String aSubjectDes)
    {
        SubjectDes = StrTool.cTrim(aSubjectDes);
    }

    public String getDept()
    {
        return Dept;
    }

    public void setDept(String aDept)
    {
        Dept = StrTool.cTrim(aDept);
    }

    public String getServiceModule()
    {
        return ServiceModule;
    }

    public void setServiceModule(String aServiceModule)
    {
        ServiceModule = StrTool.cTrim(aServiceModule);
    }

    public String getTaskCode()
    {
        return TaskCode;
    }

    public void setTaskCode(String aTaskCode)
    {
        TaskCode = StrTool.cTrim(aTaskCode);
    }

    public String getTaskDescribe()
    {
        return TaskDescribe;
    }

    public void setTaskDescribe(String aTaskDescribe)
    {
        TaskDescribe = StrTool.cTrim(aTaskDescribe);
    }

    public String getLogType()
    {
        return LogType;
    }

    public void setLogType(String aLogType)
    {
        LogType = StrTool.cTrim(aLogType);
    }

    public String getSwitch()
    {
        return Switch;
    }

    public void setSwitch(String aSwitch)
    {
        Switch = StrTool.cTrim(aSwitch);
    }


    /**
     * 使用另外一个 LogSubjectSchema 对象给 Schema 赋值
     * @param: cLogSubjectSchema LogSubjectSchema
     */
    public void setSchema(LogSubjectSchema cLogSubjectSchema)
    {
        this.SubjectID = cLogSubjectSchema.getSubjectID();
        this.SubjectDes = cLogSubjectSchema.getSubjectDes();
        this.Dept = cLogSubjectSchema.getDept();
        this.ServiceModule = cLogSubjectSchema.getServiceModule();
        this.TaskCode = cLogSubjectSchema.getTaskCode();
        this.TaskDescribe = cLogSubjectSchema.getTaskDescribe();
        this.LogType = cLogSubjectSchema.getLogType();
        this.Switch = cLogSubjectSchema.getSwitch();
    }

    /**
     * 使用 ResultSet 中的第 i 行给 Schema 赋值
     * @param: rs ResultSet
     * @param: i int
     * @return: boolean
     */
    public boolean setSchema(ResultSet rs, int i)
    {
        try
        {
            if (rs.getString(1) == null)
                this.SubjectID = null;
            else
                this.SubjectID = rs.getString(1);
            if (rs.getString(2) == null)
                this.SubjectDes = null;
            else
                this.SubjectDes = rs.getString(2);
            if (rs.getString(3) == null)
                this.Dept = null;
            else
                this.Dept = rs.getString(3);
            if (rs.getString(4) == null)
                this.ServiceModule = null;
            else
                this.ServiceModule = rs.getString(4);
            if (rs.getString(5) == null)
                this.TaskCode = null;
            else
                this.TaskCode = rs.getString(5);
            if (rs.getString(6) == null)
                this.TaskDescribe = null;
            else
                this.TaskDescribe = rs.getString(6);
            if (rs.getString(7) == null)
                this.LogType = null;
            else
                this.LogType = rs.getString(7);
            if (rs.getString(8) == null)
                this.Switch = null;
            else
                this.Switch = rs.getString(8);
        }
        catch (SQLException sqle)
        {
            sqle.printStackTrace();
            // @@错误处理
            CError tError = new CError();
            tError.moduleName = "LogSubjectSchema";
            tError.functionName = "setSchema";
            tError.errorMessage = sqle.toString();
            this.mErrors.addOneError(tError);
            return false;
        }
        return true;
    }

    public LogSubjectSchema getSchema()
    {
        LogSubjectSchema aLogSubjectSchema = new LogSubjectSchema();
        aLogSubjectSchema.setSchema(this);
        return aLogSubjectSchema;
    }

    public LogSubjectDB getDB()
    {
        LogSubjectDB aDBOper = new LogSubjectDB();
        aDBOper.setSchema(this);
        return aDBOper;
    }

    /**
     * 数据打包，按 XML 格式打包
     * @return: String 返回打包后字符串
     */
    public String encode()
    {
        StringBuffer strReturn = new StringBuffer(256);
        strReturn.append(StrTool.cTrim(SubjectID));
        strReturn.append(SysConst.PACKAGESPILTER);
        strReturn.append(StrTool.cTrim(SubjectDes));
        strReturn.append(SysConst.PACKAGESPILTER);
        strReturn.append(StrTool.cTrim(Dept));
        strReturn.append(SysConst.PACKAGESPILTER);
        strReturn.append(StrTool.cTrim(ServiceModule));
        strReturn.append(SysConst.PACKAGESPILTER);
        strReturn.append(StrTool.cTrim(TaskCode));
        strReturn.append(SysConst.PACKAGESPILTER);
        strReturn.append(StrTool.cTrim(TaskDescribe));
        strReturn.append(SysConst.PACKAGESPILTER);
        strReturn.append(StrTool.cTrim(LogType));
        strReturn.append(SysConst.PACKAGESPILTER);
        strReturn.append(StrTool.cTrim(Switch));
        return strReturn.toString();
    }

    /**
     * 数据解包
     * @param: strMessage String 包含一条纪录数据的字符串
     * @return: boolean
     */
    public boolean decode(String strMessage)
    {
        try
        {
            SubjectID = StrTool.getStr(strMessage, 1, SysConst.PACKAGESPILTER);
            SubjectDes = StrTool.getStr(strMessage, 2, SysConst.PACKAGESPILTER);
            Dept = StrTool.getStr(strMessage, 3, SysConst.PACKAGESPILTER);
            ServiceModule = StrTool.getStr(strMessage, 4, SysConst.PACKAGESPILTER);
            TaskCode = StrTool.getStr(strMessage, 5, SysConst.PACKAGESPILTER);
            TaskDescribe = StrTool.getStr(strMessage, 6, SysConst.PACKAGESPILTER);
            LogType = StrTool.getStr(strMessage, 7, SysConst.PACKAGESPILTER);
            Switch = StrTool.getStr(strMessage, 8, SysConst.PACKAGESPILTER);
        }
        catch (NumberFormatException ex)
        {
            // @@错误处理
            CError tError = new CError();
            tError.moduleName = "LogSubjectSchema";
            tError.functionName = "decode";
            tError.errorMessage = ex.toString();
            this.mErrors.addOneError(tError);
            return false;
        }
        return true;
    }

    /**
     * 取得对应传入参数的String形式的字段值
     * @param: FCode String 希望取得的字段名
     * @return: String
     * 如果没有对应的字段，返回""
     * 如果字段值为空，返回"null"
     */
    public String getV(String FCode)
    {
        String strReturn = "";
        if (FCode.equalsIgnoreCase("SubjectID"))
        {
            strReturn = StrTool.cTrim(SubjectID);
        }
        if (FCode.equalsIgnoreCase("SubjectDes"))
        {
            strReturn = StrTool.cTrim(SubjectDes);
        }
        if (FCode.equalsIgnoreCase("Dept"))
        {
            strReturn = StrTool.cTrim(Dept);
        }
        if (FCode.equalsIgnoreCase("ServiceModule"))
        {
            strReturn = StrTool.cTrim(ServiceModule);
        }
        if (FCode.equalsIgnoreCase("TaskCode"))
        {
            strReturn = StrTool.cTrim(TaskCode);
        }
        if (FCode.equalsIgnoreCase("TaskDescribe"))
        {
            strReturn = StrTool.cTrim(TaskDescribe);
        }
        if (FCode.equalsIgnoreCase("LogType"))
        {
            strReturn = StrTool.cTrim(LogType);
        }
        if (FCode.equalsIgnoreCase("Switch"))
        {
            strReturn = StrTool.cTrim(Switch);
        }
        if (strReturn.equals(""))
        {
            strReturn = "null";
        }
        return strReturn;
    }

    /**
     * 取得Schema中指定索引值所对应的字段值
     * @param: nFieldIndex int 指定的字段索引值
     * @return: String
     * 如果没有对应的字段，返回""
     * 如果字段值为空，返回"null"
     */
    public String getV(int nFieldIndex)
    {
        String strFieldValue = "";
        switch (nFieldIndex)
        {
            case 0:
                strFieldValue = StrTool.cTrim(SubjectID);
                break;
            case 1:
                strFieldValue = StrTool.cTrim(SubjectDes);
                break;
            case 2:
                strFieldValue = StrTool.cTrim(Dept);
                break;
            case 3:
                strFieldValue = StrTool.cTrim(ServiceModule);
                break;
            case 4:
                strFieldValue = StrTool.cTrim(TaskCode);
                break;
            case 5:
                strFieldValue = StrTool.cTrim(TaskDescribe);
                break;
            case 6:
                strFieldValue = StrTool.cTrim(LogType);
                break;
            case 7:
                strFieldValue = StrTool.cTrim(Switch);
                break;
            default:
                strFieldValue = "";
        }
        if (strFieldValue.equals(""))
        {
            strFieldValue = "null";
        }
        return strFieldValue;
    }

    /**
     * 设置对应传入参数的String形式的字段值
     * @param: FCode String 需要赋值的对象
     * @param: FValue String 要赋的值
     * @return: boolean
     */
    public boolean setV(String FCode, String FValue)
    {
        if (StrTool.cTrim(FCode).equals(""))
            return false;

        if (FCode.equalsIgnoreCase("SubjectID"))
        {
            if (FValue != null)
            {
                SubjectID = FValue.trim();
            }
            else
                SubjectID = null;
        }
        if (FCode.equalsIgnoreCase("SubjectDes"))
        {
            if (FValue != null)
            {
                SubjectDes = FValue.trim();
            }
            else
                SubjectDes = null;
        }
        if (FCode.equalsIgnoreCase("Dept"))
        {
            if (FValue != null)
            {
                Dept = FValue.trim();
            }
            else
                Dept = null;
        }
        if (FCode.equalsIgnoreCase("ServiceModule"))
        {
            if (FValue != null)
            {
                ServiceModule = FValue.trim();
            }
            else
                ServiceModule = null;
        }
        if (FCode.equalsIgnoreCase("TaskCode"))
        {
            if (FValue != null)
            {
                TaskCode = FValue.trim();
            }
            else
                TaskCode = null;
        }
        if (FCode.equalsIgnoreCase("TaskDescribe"))
        {
            if (FValue != null)
            {
                TaskDescribe = FValue.trim();
            }
            else
                TaskDescribe = null;
        }
        if (FCode.equalsIgnoreCase("LogType"))
        {
            if (FValue != null)
            {
                LogType = FValue.trim();
            }
            else
                LogType = null;
        }
        if (FCode.equalsIgnoreCase("Switch"))
        {
            if (FValue != null)
            {
                Switch = FValue.trim();
            }
            else
                Switch = null;
        }
        return true;
    }

    public boolean equals(Object otherObject)
    {
        if (this == otherObject)
            return true;
        if (otherObject == null)
            return false;
        if (getClass() != otherObject.getClass())
            return false;
        LogSubjectSchema other = (LogSubjectSchema) otherObject;
        return
                (SubjectID == null ? other.getSubjectID() == null : SubjectID.equals(other.getSubjectID()))
                        && (SubjectDes == null ? other.getSubjectDes() == null : SubjectDes.equals(other.getSubjectDes()))
                        && (Dept == null ? other.getDept() == null : Dept.equals(other.getDept()))
                        && (ServiceModule == null ? other.getServiceModule() == null : ServiceModule.equals(other.getServiceModule()))
                        && (TaskCode == null ? other.getTaskCode() == null : TaskCode.equals(other.getTaskCode()))
                        && (TaskDescribe == null ? other.getTaskDescribe() == null : TaskDescribe.equals(other.getTaskDescribe()))
                        && (LogType == null ? other.getLogType() == null : LogType.equals(other.getLogType()))
                        && (Switch == null ? other.getSwitch() == null : Switch.equals(other.getSwitch()));
    }

    /**
     * 取得Schema拥有字段的数量
     * @return: int
     */
    public int getFieldCount()
    {
        return FIELDNUM;
    }

    /**
     * 取得Schema中指定字段名所对应的索引值
     * 如果没有对应的字段，返回-1
     * @param: strFieldName String
     * @return: int
     */
    public int getFieldIndex(String strFieldName)
    {
        if (strFieldName.equals("SubjectID"))
        {
            return 0;
        }
        if (strFieldName.equals("SubjectDes"))
        {
            return 1;
        }
        if (strFieldName.equals("Dept"))
        {
            return 2;
        }
        if (strFieldName.equals("ServiceModule"))
        {
            return 3;
        }
        if (strFieldName.equals("TaskCode"))
        {
            return 4;
        }
        if (strFieldName.equals("TaskDescribe"))
        {
            return 5;
        }
        if (strFieldName.equals("LogType"))
        {
            return 6;
        }
        if (strFieldName.equals("Switch"))
        {
            return 7;
        }
        return -1;
    }

    /**
     * 取得Schema中指定索引值所对应的字段名
     * 如果没有对应的字段，返回""
     * @param: nFieldIndex int
     * @return: String
     */
    public String getFieldName(int nFieldIndex)
    {
        String strFieldName = "";
        switch (nFieldIndex)
        {
            case 0:
                strFieldName = "SubjectID";
                break;
            case 1:
                strFieldName = "SubjectDes";
                break;
            case 2:
                strFieldName = "Dept";
                break;
            case 3:
                strFieldName = "ServiceModule";
                break;
            case 4:
                strFieldName = "TaskCode";
                break;
            case 5:
                strFieldName = "TaskDescribe";
                break;
            case 6:
                strFieldName = "LogType";
                break;
            case 7:
                strFieldName = "Switch";
                break;
            default:
                strFieldName = "";
        }
        return strFieldName;
    }

    /**
     * 取得Schema中指定字段名所对应的字段类型
     * 如果没有对应的字段，返回Schema.TYPE_NOFOUND
     * @param: strFieldName String
     * @return: int
     */
    public int getFieldType(String strFieldName)
    {
        if (strFieldName.equals("SubjectID"))
        {
            return Schema.TYPE_STRING;
        }
        if (strFieldName.equals("SubjectDes"))
        {
            return Schema.TYPE_STRING;
        }
        if (strFieldName.equals("Dept"))
        {
            return Schema.TYPE_STRING;
        }
        if (strFieldName.equals("ServiceModule"))
        {
            return Schema.TYPE_STRING;
        }
        if (strFieldName.equals("TaskCode"))
        {
            return Schema.TYPE_STRING;
        }
        if (strFieldName.equals("TaskDescribe"))
        {
            return Schema.TYPE_STRING;
        }
        if (strFieldName.equals("LogType"))
        {
            return Schema.TYPE_STRING;
        }
        if (strFieldName.equals("Switch"))
        {
            return Schema.TYPE_STRING;
        }
        return Schema.TYPE_NOFOUND;
    }

    /**
     * 取得Schema中指定索引值所对应的字段类型
     * 如果没有对应的字段，返回Schema.TYPE_NOFOUND
     * @param: nFieldIndex int
     * @return: int
     */
    public int getFieldType(int nFieldIndex)
    {
        int nFieldType = Schema.TYPE_NOFOUND;
        switch (nFieldIndex)
        {
            case 0:
                nFieldType = Schema.TYPE_STRING;
                break;
            case 1:
                nFieldType = Schema.TYPE_STRING;
                break;
            case 2:
                nFieldType = Schema.TYPE_STRING;
                break;
            case 3:
                nFieldType = Schema.TYPE_STRING;
                break;
            case 4:
                nFieldType = Schema.TYPE_STRING;
                break;
            case 5:
                nFieldType = Schema.TYPE_STRING;
                break;
            case 6:
                nFieldType = Schema.TYPE_STRING;
                break;
            case 7:
                nFieldType = Schema.TYPE_STRING;
                break;
            default:
                nFieldType = Schema.TYPE_NOFOUND;
        }
        return nFieldType;
    }
}
